import { reqGoodsDetails } from "@/api";
//Detail的VUEX模块
//VUE中的四个核心概念
const state = {
    //存储数据
    goodsDetails:{},
};
const mutations = {
    //直接修改数据
    RECEIVE_GOODSDETAILS(state,goodsDetails){
        state.goodsDetails = goodsDetails;
    },
};
const actions = {
    //与组件当中的用户对接
    //一般是异步发送请求
    //提交mutations
    async getGoodsDetails({commit},skuId){
        const result = await reqGoodsDetails(skuId);
        if(result.code === 200) {
            commit("RECEIVE_GOODSDETAILS",result.data);
        }
    }
};
const getters = {
    //后面用来简化数据的
    categoryView(state){
        return state.goodsDetails.categoryView || {};
    },
    skuInfo(state){
        return state.goodsDetails.skuInfo || {};
    },
    spuSaleAttrList(state){
        return state.goodsDetails.spuSaleAttrList || [];
    }
    
}

export default{
    state,
    mutations,
    actions,
    getters,
};